package cn.cvs.pojo;

import com.alibaba.fastjson.annotation.JSONField;
import org.hibernate.validator.constraints.Length;
import org.springframework.context.annotation.Scope;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 系统用户类
 * @author project.cvs.team
 */
@Scope("prototype")
@Component
public class SysUser implements java.io.Serializable {
	private Integer id; 			//id
    @Length(min = 3,max = 12,message = "长度不对哦")
	private String account; 		//账号
	private String password; 		//密码
    @Length(min = 4,max = 16,message = "自己想")
	private String realName; 		//真实姓名
	private Integer roleId;	    	//角色id
	private String phone;   		//电话
	private String address; 		//地址
	private Integer sex;	 		//性别
    @JSONField(format = "yyyy-MM-dd")//后台->客户端后台数据
    @DateTimeFormat(pattern = "yyyy-MM-dd")//客户端->后台
	private Date birthday;  		//出生日期
	private Integer createdUserId; 	//创建人id
    @JSONField(format = "yyyy-MM-dd")//后台->客户端后台数据
    @DateTimeFormat(pattern = "yyyy-MM-dd")//客户端->后台
	private Date createdTime; 		//创建时间
	private Integer updatedUserId; 	//修改人id
    @DateTimeFormat(pattern = "yyyy-MM-dd")//客户端->后台
	private Date updatedTime;   	//修改时间
	
	private Integer age;			//用户年龄

	//扩展属性 角色名称
	private String userRoleName;
	private String idPicPath;//身份照的图片路径
    private String workPicPath;//工作证照

    public String getWorkPicPath() {
        return workPicPath;
    }

    public void setWorkPicPath(String workPicPath) {
        this.workPicPath = workPicPath;
    }

    public String getIdPicPath() {
        return idPicPath;
    }

    public void setIdPicPath(String idPicPath) {
        this.idPicPath = idPicPath;
    }

    //多对1 association 关联属性 提供嵌套关系的对象
	private SysRole sysRole;

	//1对多 collection   用户的地址
    private List<Address> addres;

    public List<Address> getAddres() {
        return addres;
    }

    public void setAddres(List<Address> addres) {
        this.addres = addres;
    }

    public SysRole getSysRole() {
		return sysRole;
	}

	public void setSysRole(SysRole sysRole) {
		this.sysRole = sysRole;
	}

	public String getUserRoleName() {
		return userRoleName;
	}

	public void setUserRoleName(String userRoleName) {
		this.userRoleName = userRoleName;
	}

	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	
	public String getRealName() {
		return realName;
	}
	public void setRealName(String realName) {
		this.realName = realName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getAccount() {
		return account;
	}
	public void setAccount(String account) {
		this.account = account;
	}
	public Integer getRoleId() {
		return roleId;
	}
	public void setRoleId(Integer role) {
		this.roleId = role;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public Integer getSex() {
		return sex;
	}
	public void setSex(Integer sex) {
		this.sex = sex;
	}
	public Date getBirthday() {
		return birthday;
	}
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	public Integer getCreatedUserId() {
		return createdUserId;
	}
	public void setCreatedUserId(Integer createdUserId) {
		this.createdUserId = createdUserId;
	}
	public Date getCreatedTime() {
		return createdTime;
	}
	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}
	public Integer getUpdatedUserId() {
		return updatedUserId;
	}
	public void setUpdatedUserId(Integer updatedUserId) {
		this.updatedUserId = updatedUserId;
	}
	public Date getUpdatedTime() {
		return updatedTime;
	}
	public void setUpdatedTime(Date updatedTime) {
		this.updatedTime = updatedTime;
	}
	public void setAge(Integer age) {
		this.age = age;
	}

	public Integer getAge() {
        Date date=new Date();
        int age = date.getYear() - birthday.getYear();
        return age;
	}

    @Override
    public String toString() {
        return "SysUser{" +
                "id=" + id +
                ", account='" + account + '\'' +
                ", password='" + password + '\'' +
                ", realName='" + realName + '\'' +
                ", roleId=" + roleId +
                ", phone='" + phone + '\'' +
                ", address='" + address + '\'' +
                ", sex=" + sex +
                ", birthday=" + birthday +
                ", createdUserId=" + createdUserId +
                ", createdTime=" + createdTime +
                ", updatedUserId=" + updatedUserId +
                ", updatedTime=" + updatedTime +
                ", age=" + age +
                ", userRoleName='" + userRoleName + '\'' +
                ", sysRole=" + sysRole +
                ", addres=" + addres +
                '}';
    }
    public String show(){
        return "SysUser{" +
                "id=" + id +
                ", realName='" + realName + '\'' +
                ", addres=" + addres +
                '}';
    }
}
